package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.SysRole;
import com.example.demo.entity.SysUserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper extends BaseMapper<SysRole> {

    @Select("select * from t_user_role where user_id = #{userId}")
    List<SysUserRole> getUserRoleByUserId(Integer userId);

    @Select("select * from t_role where comment = #{comment}")
    SysRole getRoleByName(String comment);

    @Delete("delete from t_user_role where user_id = #{userId}")
    void deleteRoleByUserId(Integer userId);

    @Insert("insert into t_user_role(user_id, role_id) values(#{userId}, #{roleId})")
    void insertUserRole(Integer userId, Integer roleId);
}
